package junit.source.pattern.chain;

import org.junit.runners.model.FrameworkMethod;

import java.util.List;

public class RunAfters extends Statement {

    Statement next;

    List<FrameworkMethod> afterMethods;

    Object target;

    public RunAfters(Statement next, List<FrameworkMethod> afterMethods, Object target) {
        this.next = next;
        this.afterMethods = afterMethods;
        this.target = target;
    }

    @Override
    public void evaluate() throws Throwable {
        try {
            next.evaluate();
        } catch (Throwable e) {

        } finally {
            for (FrameworkMethod afterMethod : afterMethods) {
                afterMethod.invokeExplosively(target);
            }
        }
    }
}
